package wql.aaa.service.impl;

import com.aaa.entity.TbHeadNav;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wql.aaa.dao.HeadNovDao;
import wql.aaa.service.HeadNovService;
import wql.aaa.vo.FormData;

import java.util.List;

/**
 * @author wql
 * @version 1.0
 * @date 2023/2/27 11:03
 */
@Service
public class HeadNovServiceImpl implements HeadNovService {

    @Autowired
    private HeadNovDao headNovDao;

    /**
     * 查询
     * @param currentPage
     * @param pageSize
     * @param formData
     * @return
     */
    @Override
    public Result findAll(int currentPage, int pageSize, FormData formData) {
        PageHelper.startPage(currentPage,pageSize);
        List<TbHeadNav> list = headNovDao.findAll(formData);
        PageInfo<TbHeadNav> info = new PageInfo<>(list);
        return new Result(2000,"查询成功",info);
    }

    /**
     * 添加
     * @param tbHeadNav
     * @return
     */
    @Override
    public Result add(TbHeadNav tbHeadNav) {
//        TbHeadNav tbHeadNav1 = new TbHeadNav();
//        tbHeadNav1.setHeadName(tbHeadNav.getHeadName());
//        tbHeadNav1.setIsDeleted("0");
//        tbHeadNav1.setSkipWay(tbHeadNav.getSkipWay());
//        headNovDao.insert(tbHeadNav1);
        QueryWrapper<TbHeadNav> wrapper = new QueryWrapper<>();
        wrapper.eq("head_id",tbHeadNav.getHeadId());
        TbHeadNav tbHeadNav1 = headNovDao.selectOne(wrapper);
        tbHeadNav1.setIsAdd(0);
        headNovDao.updateById(tbHeadNav1);
        return new Result(2000,"添加成功");
    }

    /**
     * 修改
     * @param tbHeadNav
     * @return
     */
    @Override
    public Result update(TbHeadNav tbHeadNav) {
        headNovDao.updateById(tbHeadNav);
        return new Result(2000,"修改成功");
    }

    /**
     * 修改状态
     * @param headId
     * @param isDisable
     * @return
     */
    @Override
    public Result updateIsDisabled(Integer headId, String isDisable) {
        headNovDao.changeIsDisable(headId,isDisable);
        return new Result(2000,"状态修改成功");
    }

    /**
     * 删除
     * @param headId
     * @return
     */
    @Override
    public Result dalete(Integer headId) {
        headNovDao.deleteById(headId);
        return new Result(2000,"删除成功");
    }

    @Override
    public Result selectType() {
        List<TbHeadNav> tbHeadNavs = headNovDao.selectType();
        return new Result(2000,"查询成功",tbHeadNavs);
    }


}
